package cn.lzd.mr.case1;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by lzd on 2018/5/31.
 */
public class MDemo extends Mapper<LongWritable, Text, Text, Bean> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String text = value.toString();
        String[] split = text.split(" ");
        List<String> res = Stream.of(split).filter((x) -> StringUtils.isNotBlank(x)).collect(Collectors.toList());

        String phone = res.get(1);
        int upflow = Integer.parseInt(res.get(res.size() - 3));
        int downflow = Integer.parseInt(res.get(res.size() - 2));

        context.write(new Text(phone), new Bean(upflow, downflow, phone));
    }
}
